"""

Computational Economics
03: Modules
http://johnstachurski.net/lectures/modules.html

"""


import math, random


"""
    Problem 1:

    * Simulate a draw from Y = max{|X_1|,...,|X_10|}, where X_i ~ N(0, 1)
    * And print out the result
          o Hint: Use list comprehensions
"""
Y = max([abs(random.normalvariate(0, 1)) for i in range(10)])
print Y


"""
    Problem 2:

    * Simulate a draw from Y ~ Bin(n, 0.5) using random.choice()
          o num of successes in n indep trials with success prob 0.5
          o E.g., num of heads in n flips of fair coin
          o The value of n is read in from the user at run time
"""
# prompt
prompt = 'Enter number of trials: '
num_trials = int(raw_input(prompt))

# run trials
num_heads = [1 for n in range(num_trials) if random.choice(['h','t']) == 't']
print '%s heads in %s coin flips' % (sum(num_heads), num_trials)


print '%s: ok' % (__file__)
